β‘ How a GitHub Actions Runner Works (Step by Step)
GitHub Actions runners execute workflows when triggered by events like code pushes, pull requests, or scheduled tasks. Hereβs a step-by-step breakdown of how it works:
π 1. Triggering the Pipelineβ
- You push or pull code to GitHub (or trigger any defined event). π
- GitHub detects this event and assigns the job to an available runner (either GitHub-hosted or self-hosted). π₯οΈ
π Example Triggers:
push
tomain
branch π€- Opening a
pull request
π - A
cron job
running at scheduled times β°
π₯ 2. Runner Fetches the Codeβ
- The runner starts on a machine (either a GitHub-provided VM or your own self-hosted server). ποΈ
- It clones (downloads) the latest code from your GitHub repository. π
- The runner sets up the working environment as defined in the YAML workflow file.
π οΈ 3. Runner Executes the Stepsβ
- It follows the instructions defined in the GitHub Actions YAML file (
.github/workflows/your-workflow.yml
). - Each step is executed in the specified order.
π Example Steps:
β
Set up Node.js π§
β
Install dependencies (e.g., npm install
) π¦
β
Run tests (e.g., npm test
) π§ͺ
β
Build the project (e.g., npm run build
) ποΈ
β
Lint and format code (e.g., eslint . --fix
) π¨
π‘ 4. Deploying to Another Server (Optional Step)β
- The runner itself does not run your application; it only executes tasks like testing, building, and deploying.
- If your YAML file includes an SSH step, the runner will:
- π Use SSH to connect to the production server.
- π€ Copy the built files to the production server using
rsync
orscp
. - π Restart services (e.g.,
pm2 restart app
,docker-compose up -d
).
π― Key Takeawaysβ
β
GitHub Actions automates testing, building, and deployment processes.
β
Runners execute jobs based on YAML workflow instructions.
β
Self-hosted runners provide more control, while GitHub-hosted runners are managed automatically.
β
Deployments often involve SSH & file transfers to production environments.
π‘ With GitHub Actions, you can automate your entire CI/CD pipeline effortlessly! ππ₯